package com.sxt.draw;

import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class DrawDemo extends JPanel {

	private int x = 0;
	private int y = 0;

	public static void main(String[] args) {
		JFrame frame = new JFrame("画图板");
		frame.setVisible(true);
		frame.setSize(500, 500);
		frame.setLocation(200, 200);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.add(new DrawDemo());
	}

	@Override
	public void paint(Graphics g) {
		// TODO Auto-generated method stub
		super.paint(g);

		g.drawLine(5, 5, x, y);

		this.addMouseListener(new MouseAdapter() {

			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				super.mousePressed(e);
				x = e.getX();
				y = e.getY();
				repaint();
			}

		});
	}

	public DrawDemo() {

	}

}
